class Solution {
public:
    TreeNode* pre = NULL;                                  
    TreeNode* convertBST(TreeNode* root) {
        if(!root){
            return NULL;
        }
        convertBST(root->right);
        
        if(pre){
            root->val += pre->val;
        }
        pre = root;
        
        convertBST(root->left);
        
        return root;
    }
};

